package com.wangjiang.foundation.mybatis.convert;

import cn.hutool.core.bean.BeanUtil;
import com.wangjiang.foundation.common.exception.BeanMapperException;
import com.wangjiang.foundation.common.exception.CommonException;

public interface ConvertTo<E> {

    Class<E> getEntityClass();

    default E convertTo() throws BeanMapperException{
        E entity;
        try {
            entity = getEntityClass().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
            throw new CommonException(e.getMessage());
        }
        BeanUtil.copyProperties(this, entity);
        return entity;
    }

}
